/*
 * rosa_queues.h
 *
 * Created: 2014-12-03 13:46:45
 *  Author: eds04001
 */ 


#ifndef ROSA_QUEUES_H_
#define ROSA_QUEUES_H_
#include "kernel/rosa_task.h"

extern tcb *readyQueueHead;
extern tcb *waitingQueueHead;
extern tcb *deleteQueue;
extern tcb *blockedQueueHead;

/// Removes specified task from specified queue
void rosa_removeFromQueue(tcb *task, tcb **queueHead);

// READY QUEUE: tasks that are ready to execute

/// Adds the specified task to the ready queue. The task is placed
/// just before the first task with a LOWER dynamic priority.
void rosa_addToReadyQueue(tcb *newTask);
/// Adds the specified task to the ready queue. The task is set as the
/// second task in the queue
void rosa_addToReadyQueueFront(tcb *newTask);
/// Removes the first task in the ready queue (the one with the highest priority) and returns it
tcb* rosa_popHighestPriorityTaskFromReadyQueue(void);
/// Returns length of ready queue
unsigned int readyQueueLength(void);

// WAITING QUEUE: tasks that have delayed or blocked on a semaphore with a timeout

/// Adds specified task to the waiting queue, with the specified wakeup time
void rosa_addToWaitingQueue(tcb *newTask);
/// Removes the first task in the waiting queue (the one with the shortest waiting time)
/// and adds it to the ready queue
int rosa_moveFirstTaskFromWaitingToReady(void);
/// Returns length of waiting queue
unsigned int waitingQueueLength(void);

// BLOCKED QUEUE: tasks that are blocked indefinitely

/// Adds the specified task to the blocked queue
void rosa_addToBlocked(tcb  *task);
/// Returns the length of the blocked queue
int rosa_blockedQueueLength();

// DELETE QUEUE: tasks that have terminated and are waiting for memory deallocation

/// Adds the specified task to the delete queue
int rosa_addToDelete(tcb  *task);
/// Removes the first task from the delete queue and returns it
tcb* rosa_removeFromDelete(void);
/// Returns the length of the delete queue
unsigned int deleteQueueLength(void);

#endif /* ROSA_QUEUES_H_ */